/**
 * Created with JetBrains WebStorm.
 * User: rekey
 * Date: 8/9/13
 * Time: 4:08
 * To change this template use File | Settings | File Templates.
 */
function createList(current, pages, pageCount) {
    var list = [];
    var step = Math.floor(pageCount / 2);
    var start = current - step;
    var end = current + step;
    if (start < 1) {
        start = 1;
        end = pageCount;
    }
    if (end > pages) {
        end = pages;
    }
    end++;
    for (; start < end; start++) {
        list.push(start);
    }
    return list;
}

function getPage(current, count, pageCount) {
    pageCount = pageCount || 7;
    var pages = Math.ceil(count / 10);
    return {
        list : createList(current, pages, pageCount),
        current : current,
        prev : current > 1 ? current - 1 : null,
        next : current < pages ? current - 0 + 1 : null
    };
}

module.exports = {
    create : getPage
};
